/** 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.tompai.foreign.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tompai.common.model.CataLog;
import com.tompai.common.model.Film;
import com.tompai.foreign.service.CataLogService;
import com.tompai.foreign.service.FilmService;

import springfox.documentation.annotations.ApiIgnore;

/**
 * 开始
 *
 * @author liinux@qq.com
 * @date 2019/10/6
 */
@Controller
@ApiIgnore
public class StartController {
	@Resource
	private FilmService filmService;

	@Resource
	private CataLogService cataLogService;

	@RequestMapping(value = { "/index.html", "" })
	public String index(ModelMap map) {
		List<CataLog> cataLogList = cataLogService.listIsUse();
		map.addAttribute("cataLogList", cataLogList);
		/**
		 * 查询推荐
		 */

		List<List<Film>> list = new ArrayList<>();
		for (int i = 0; i < cataLogList.size(); i++) {

			List<Film> film = filmService.listByCataLogId(cataLogList.get(i).getId());
			if (film.size() != 0) {
				list.add(film);
			}
		}
		map.addAttribute("filmTuijian", list);

		List<Object> list1 = new ArrayList<Object>();
		for (int i = 0; i < cataLogList.size(); i++) {

			List<Film> film = filmService.listByEvaluation(cataLogList.get(i).getId());
			if (film.size() != 0) {
				list1.add(film);
			}
		}
		map.addAttribute("filmPaiHang", list1);
		return "index/home";
	}

	@RequestMapping(value = "/note.html")
	public String note(ModelMap map) {
		List<CataLog> cataLogList = cataLogService.listIsUse();
		map.addAttribute("cataLogList", cataLogList);
		return "index/note";
	}

	@RequestMapping(value = "/error.html")
	public String error() {
		return "index/error";
	}

}
